cmake_minimum_required(VERSION 3.6)

pkg_check_modules(LIBDRM QUIET libdrm)
pkg_check_modules(X11 QUIET x11)
pkg_check_modules(EPOXY QUIET epoxy)
pkg_check_modules(QTCORE QUIET Qt5Core)
pkg_check_modules(QTWIDGETS QUIET Qt5Widgets)

set(SRC "preview.cpp")
set(TARGET_LIBS "")

set(DRM_FOUND 0)
if (LIBDRM_FOUND)
    message(STATUS "LIBDRM_LINK_LIBRARIES=${LIBDRM_LINK_LIBRARIES}")
    include_directories(${LIBDRM_INCLUDE_DIRS})
    set(TARGET_LIBS ${TARGET_LIBS} ${LIBDRM_LIBRARIES})
    set(SRC ${SRC} drm_preview.cpp)
    set(DRM_FOUND 1)
else()
    message(WARNING "LIBDRM not found, this display mode will be unavailable!")
endif()

set(EGL_FOUND 0)
if (X11_FOUND AND EPOXY_FOUND)
    message(STATUS "X11_LINK_LIBRARIES=${X11_LINK_LIBRARIES}")
    message(STATUS "EPOXY_LINK_LIBRARIES=${EPOXY_LINK_LIBRARIES}")
    set(TARGET_LIBS ${TARGET_LIBS} ${X11_LIBRARIES} ${EPOXY_LIBRARIES})
    set(SRC ${SRC} egl_preview.cpp)
    set(EGL_FOUND 1)
else()
    message(WARNING "EGL libraries not found, this display mode will be unavailable!")
endif()

set(QT_FOUND 0)
if (QTCORE_FOUND AND QTWIDGETS_FOUND)
    message(STATUS "QTCORE_LINK_LIBRARIES=${QTCORE_LINK_LIBRARIES}")
    message(STATUS "QTCORE_INCLUDE_DIRS=${QTCORE_INCLUDE_DIRS}")
    include_directories(${QTCORE_INCLUDE_DIRS} ${QTWIDGETS_INCLUDE_DIRS})
    set(TARGET_LIBS ${TARGET_LIBS} ${QTCORE_LIBRARIES} ${QTWIDGETS_LIBRARIES})
    set(SRC ${SRC} qt_preview.cpp)
    set(QT_FOUND 1)
else()
    message(STATUS "QT not found, this display mode will be unavailable")
endif()

add_library(preview null_preview.cpp ${SRC})
target_link_libraries(preview ${TARGET_LIBS})

target_compile_definitions(preview PUBLIC LIBDRM_PRESENT=${DRM_FOUND})
target_compile_definitions(preview PUBLIC LIBEGL_PRESENT=${EGL_FOUND})
target_compile_definitions(preview PUBLIC QT_PRESENT=${QT_FOUND})

install(TARGETS preview LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

